package xmltomce.properties;

import static org.junit.Assert.*;

import java.io.File;

import org.junit.Test;


public class PropertiesTest {
	
	public void tearDown(){
		getPropertyFile().delete();
	}
	
	private File getPropertyFile(){
		return new File(PersistentProperties.getPropertiesFilePath());
	}
	
	private PersistentProperties getMovieSyncProps(){
		return PersistentProperties.getInstance(new MovieSyncProperties());
	}
	
	@Test
	public void testSavePersistent(){
		getPropertyFile().delete();
		getMovieSyncProps().save();
		assertTrue(getPropertyFile().isFile());
	}
	
	@Test
	public void testLoadWithDefaultValues(){
		getPropertyFile().delete();
		String expectedVobFolder = "D:\\JavaWorkspace\\MovieCollectorToMce\\testdata\\dvds";
		String vobFolder = getMovieSyncProps().getProperty("dvdVobFolderPath");
		assertEquals(expectedVobFolder, vobFolder);
	}
	
	@Test
	public void testPersistentPropertySaving(){
		PersistentProperties props = getMovieSyncProps();
		String testKey = "dvdVobFolderPath";
		String testPath = "C:\\temp";
		props.setProperty(testKey, testPath);
		props.save();
		assertEquals(testPath, props.getProperty(testKey));
		getPropertyFile().delete();
	}
	
}
